#include "ProblemB.h"
#include <cmath>
#include <iostream>
#include <iomanip>

int main(){
    cout << "-----ProblemC-----\n";

    ifstream inputC("input/inputC.txt");  
    if(!inputC.is_open()){  
        cerr << "Unable to open input file!" << endl;  
        exit(-1);
    }

    ProblemC C;
    string name;
    double a, b;
    int sample_num;
    inputC >> name >> a >> b >> sample_num;  // p1 p2 p3 p4
    C.print_sample_pt(a, b, sample_num, name);

    int N;
    inputC >> N; // p5

    BSpline<3> cubic = cardinal_3D(a, b, C);
    inputC >> name;  // p6
    cubic.print_plot_data(sample_num, name);

    vector<double> sites;
    double x, delta;
    inputC >> x >> delta; // p7 p8
    for(int i = 0; i < N-1; i++){
        sites.push_back(x);
        x += delta;
    }
    BSpline<2> quad = cardinal_2D(a, b, sites, C);
    inputC >> name;  // p9
    quad.print_plot_data(sample_num, name);
    

    cout << "-----ProblemD-----\n";
    ifstream inputD("input/inputD.txt");  
    if(!inputD.is_open()){  
        cerr << "Unable to open input file!" << endl;  
        exit(-1);
    }
    int num_of_sites;
    inputD >> num_of_sites;
    vector<double> x_sites(num_of_sites);
    for(int i = 0; i < num_of_sites; i++){
        inputD >> x_sites[i];
    }
    cout << "sites     cubic      quadratic\n";
    for(auto& site : x_sites){
        cout << setw(4) << site << ": ";
        double S3_x = cubic.get_value_at_x(site);
        double S2_x = quad.get_value_at_x(site);
        double f_x = C.f(site);
        cout << setw(12) << abs(S3_x - f_x) << " ";
        cout << setw(12) << abs(S2_x - f_x) << "\n";
    }

    return 0;
}